package com.zz.ui_demo_wedgit;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListView1Activity extends AppCompatActivity {
    private List<Map<String, Object>> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view1);
        initData();
        ListView lvSimple = findViewById(R.id.lv_simple);
        SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.listview_simple_item,
                new String[]{"id", "name", "salary"},
                new int[]{R.id.tv_simple_id, R.id.tv_simple_name, R.id.tv_simple_salary});
        lvSimple.setAdapter(adapter);
    }
    private void initData(){
        data = new ArrayList<Map<String,Object>>();
        HashMap<String,Object> item1 = new HashMap<>();
        item1.put("id", "1");
        item1.put("name","张三");
        item1.put("salary", "6004");
        data.add(item1);
        HashMap<String,Object> item2 = new HashMap<>();
        item2.put("id", "2");
        item2.put("name","李四");
        item2.put("salary", "6000");
        data.add(item2);
    }
}